/*
    SpawnSurance - Minecraft Plugin for casualty insurance of inventory contents
    Copyright (C) 2012 Ernest Pazera

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     */
package com.pdg.mcplugin.spawnsurance;

import java.io.File;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.permissions.PermissionDefault;

public class Constants {
	
	//commands
	public final static String commandSpawnSurance = "SPAWNSURANCE";
	public final static String subcommandHelp = "HELP";
	public final static String subcommandQuestion = "?";
	public final static String subcommandGet = "GET";
	public final static String subcommandCheck = "CHECK";
	public final static String subcommandSet = "SET";
	public final static String commandPropertyClaims = "CLAIMS";
	public final static String commandPropertyMaterial = "MATERIAL";
	public final static String commandPropertyMinimum = "MINIMUM";
	public final static String commandPropertyMaximum = "MAXIMUM";
	public final static String commandPropertyAcceleration = "ACCELERATION";
	public static final String commandPropertyMessageEnabled = "MESSAGE-ENABLED";
	public static final String commandPropertyMessageText = "MESSAGE-TEXT";
	public static final String commandPropertyPaySource = "PAY-SOURCE";

	//argument indices for commands
	public final static int argSubcommand = 0;
	public final static int argProperty = 1;
	public final static int argValue1 = 2;
	public final static int argValue2 = 3;
	public final static int argCountZero = 0;
	public final static int argCountSingle = 1;
	public final static int argCountDouble = 2;
	public final static int argCountTriple = 3;
	public final static int argCountQuadruple = 4;
	
	//connection string for database
	public final static String connectionString = "jdbc:sqlite:%s"+ File.separator + "spawnsurance.db";
	
	//configuration values
	public final static String configurationFile = "configuration.yml";
	public final static String configurationMaterial = "cost.material";
	public final static String configurationMinimum = "cost.minimum";
	public final static String configurationMaximum = "cost.maximum";
	public final static String configurationAcceleration = "cost.acceleration";
	public final static String configurationMessageEnabled = "message.enabled";
	public final static String configurationMessageText = "message.text";
	public static final String configurationPaySource = "paysource";
	public static final String configurationFilterState = "filter.state";
	public static final String configurationFilterMaterials = "filter.materials";
	
	//default configuration values
	public final static Material materialDefault = Material.ROTTEN_FLESH;
	public final static int minimumDefault = 1;
	public final static int maximumDefault = 64;
	public final static int accelerationDefault = 1;
	public final static boolean messageEnabledDefault = true;
	public final static String messageTextDefault = "Whew! Good thing you are covered by SpawnSurance!";
	
	//names
	public final static String pluginName = "SpawnSurance";
	public final static String classNameSQLite = "org.sqlite.JDBC";
	
	//Logger
	public final static String minecraftLoggerName = "Minecraft";
	
	//messages
	public final static String messagePluginEnabled = "["+pluginName+"] Enabled!";
	public final static String messagePluginDisable = "["+pluginName+"] Disabled!";
	public final static String messageCreatedDataFolder = "["+pluginName+"] Data folder created!";
	public final static String messageGetAcceleration = "["+pluginName+"] The current acceleration rate for spawnsurance is %d.";
	public final static String messageGetMinimum = "["+pluginName+"] The current minimum cost for spawnsurance is %d.";
	public final static String messageGetMaximum = "["+pluginName+"] The current maximum cost for spawnsurace is %d.";
	public final static String messageGetMaterial = "["+pluginName+"] The current material requires for spawnsurance is %s.";
	public final static String messageClaimsForPlayer = "["+pluginName+"] The claim count for player %s is %d.";
	public static final String messagePlayerCurrentCost = "["+pluginName+"] The current cost of coverage is %d %s.";
	public static final String messagePlayerCurrentCostVault = "["+pluginName+"] The current cost of coverage is %s.";
	public static final String messageCovered = "["+pluginName+"] Currently covered.";
	public static final String messageNotCovered = "["+pluginName+"] Currently not covered.";
	public static final String messageUsedSpawnSurance = "["+pluginName+"] %s";
	public static final String messageGetMessageText = "["+pluginName+"] The current message text for spawnsurance is \"%s\".";
	public static final String messageGetMessageEnabled = "["+pluginName+"] The current message enabled state for spawnsurance is %b.";
	public static final String messageGetPaySourceText = "["+pluginName+"] The current pay source for spawnsurance is \"%s\".";
	
	//errors
	public final static String errorCouldNotCreateDataFolder = ChatColor.RED + "["+pluginName+"] Could not create data folder!";
	public final static String errorCouldNotLoadSQLite = ChatColor.RED + "["+pluginName+"] Could not load SQLite!";
	public final static String errorCouldNotConnectToDatabase = ChatColor.RED + "["+pluginName+"] Failed to open connection to database!";
	public final static String errorCouldNotCreateInventoryTable = ChatColor.RED + "["+pluginName+"] Failed to create inventory table!";
	public final static String errorCouldNotCreateInventoryEnchantmentsTable = ChatColor.RED + "["+pluginName+"] Failed to create inventory enchantments table!";
	public final static String errorCouldNotCreateClaimsTable = ChatColor.RED + "["+pluginName+"] Failed to create claims table!";
	public final static String errorCouldNotClearPlayerInventory = ChatColor.RED + "["+pluginName+"] Could not clear player inventory!";
	public final static String errorCouldNotClearPlayerInventoryEnchantments  = ChatColor.RED + "["+pluginName+"] Could not clear player inventory enchantments!";
	public final static String errorBadCommand = ChatColor.RED + "["+pluginName+"] Bad command!  Type \"/spawnsurance\" for usage!";
	public final static String errorThereIsNoCurrentPlayer = ChatColor.RED + "["+pluginName+"] There is no current player!";
	public final static String errorCouldNotSetPlayerClaims = ChatColor.RED + "["+pluginName+"] Could not set player claims!";
	public final static String errorInvalidMaterial = ChatColor.RED + "["+pluginName+"] Invalid material!";
	public static final String errorCouldNotInsertPlayerInventoryEnchantment = ChatColor.RED + "["+pluginName+"] Could not insert player inventory enchantment!";
	public static final String errorCouldNotInsertPlayerInventory = ChatColor.RED + "["+pluginName+"] Could not insert player inventory!";
	public static final String errorCouldNotRetrievePlayerInventoryEnchantments = ChatColor.RED + "["+pluginName+"] Could not retrieve player inventory enchantments!";
	public static final String errorNoPermission = ChatColor.RED + "["+pluginName+"] You don't have permission to use this command!";
	
	//inventory table
	public final static String tableInventory = "ss_inventory";
	public final static String fieldPlayer = "player";
	public final static String fieldSlot = "slot";
	public final static String fieldType = "type";
	public final static String fieldAmount = "amount";
	public final static String fieldData = "data";
	public final static String fieldDurability = "durability";
	
	//inventory table operations
	public final static String dbCheckForInventoryTable = "SELECT `name` FROM `sqlite_master` WHERE `type`='table' AND `name`='"+tableInventory+"';";
	public final static String dbCreateInventoryTable = "CREATE TABLE IF NOT EXISTS `"+tableInventory+"` (`"+fieldPlayer+"` TEXT, `"+fieldSlot+"` INT, `"+fieldType+"` INT, `"+fieldAmount+"` INT, `"+fieldData+"` INT, `"+fieldDurability+"` INT);";
	public final static String dbClearPlayerInventory = "DELETE FROM `"+tableInventory+"` WHERE `"+fieldPlayer+"`='%s';";
	public final static String dbInsertPlayerInventory = "INSERT INTO `"+tableInventory+"` (`"+fieldPlayer+"`,`"+fieldSlot+"`,`"+fieldType+"`,`"+fieldAmount+"`,`"+fieldData+"`,`"+fieldDurability+"`) VALUES ('%s',%d,%d,%d,%d,%d)";
	public static final String dbRetrievePlayerInventory = "SELECT `"+fieldSlot+"`,`"+fieldType+"`,`"+fieldAmount+"`,`"+fieldData+"`,`"+fieldDurability+"` FROM `"+tableInventory+"` WHERE `"+fieldPlayer+"`='%s';";
	
	//inventory enchantments table
	public final static String tableInventoryEnchantments="ss_inventory_enchantments";
	//uses fieldPlayer
	//uses fieldSlot
	public final static String fieldEnchantment = "enchantment";
	public final static String fieldLevel = "level";
	
	//inventory enchantmens table operations
	public final static String dbCheckForInventoryEnchantmentsTable = "SELECT `name` FROM `sqlite_master` WHERE `type`='table' AND `name`='"+tableInventoryEnchantments+"';";
	public final static String dbCreateInventoryEnchantmentsTable = "CREATE TABLE IF NOT EXISTS `"+tableInventoryEnchantments+"` (`"+fieldPlayer+"` TEXT, `"+fieldSlot+"` INT, `"+fieldEnchantment+"` INT, `"+fieldLevel+"` INT);";
	public final static String dbClearPlayerInventoryEnchantments = "DELETE FROM `"+tableInventoryEnchantments+"` WHERE `"+fieldPlayer+"`='%s';";
	public final static String dbInsertPlayerInventoryEnchantments = "INSERT INTO `"+tableInventoryEnchantments+"` (`"+fieldPlayer+"`,`"+fieldSlot+"`,`"+fieldEnchantment+"`,`"+fieldLevel+"`) VALUES ('%s',%d,%d,%d);";
	public final static String dbRetrievePlayerInventoryEnchantments  = "SELECT `"+fieldEnchantment+"`,`"+fieldLevel+"` FROM `"+tableInventoryEnchantments+"` WHERE `"+fieldPlayer+"`='%s' AND `"+fieldSlot+"`=%d;";
	
	//claims table
	public final static String tableClaims = "ss_claims";
	//uses fieldPlayer
	public final static String fieldClaims = "claims";
	
	//claims table operations
	public final static String dbCheckForClaimsTable = "SELECT `name` FROM `sqlite_master` WHERE `type`='table' AND `name`='"+tableClaims+"';";
	public final static String dbCreateClaimsTable = "CREATE TABLE IF NOT EXISTS `"+tableClaims+"` (`"+fieldPlayer+"` TEXT UNIQUE, `"+fieldClaims+"` INT);";
	public final static String dbRetrievePlayerClaims = "SELECT `"+fieldClaims+"` FROM `"+tableClaims+"` WHERE `"+fieldPlayer+"`='%s';";
	public final static String dbDeletePlayerClaims = "DELETE FROM `"+tableClaims+"` WHERE `"+fieldPlayer+"`='%s';";
	public final static String dbInsertPlayerClaims = "INSERT INTO `"+tableClaims+"` (`"+fieldClaims+"`,`"+fieldPlayer+"`) VALUES (%d,'%s');";
	
	//permission defaults
	public static final PermissionDefault permissionUseDefault = PermissionDefault.TRUE;
	public static final PermissionDefault permissionAdminConfigurationDefault = PermissionDefault.OP;
	public static final PermissionDefault permissionAdminClaimsDefault = PermissionDefault.OP;
	
	//i hate magic numbers, even 0
	public final static int claimsZero = 0;
	public final static int costZero = 0;
	public final static int indexZero = 0;
	public static final PaySource paySourceDefault = PaySource.DEFAULT;
	
	public static final String pluginVault = "Vault";
	public static final FilterState filterDefault = FilterState.OFF;
	
}
